package com.bruce.codeFactory.designMode.observer;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author luotuan
 * @Description
 * @create 2019-03-04 21:59
 **/
public class Subject {
    private List<Observer> observers = new ArrayList<>();
    private int state;

    public int getState() {
        return state;
    }

    public void setState(int state) {
        if(state==this.state){
            return;
        }
        this.state = state;
        notifyAllObserver();
    }
    public void attch(Observer observer){
        observers.add(observer);
    }
    private void notifyAllObserver(){
        observers.stream().forEach(Observer::update);
    }
}
